﻿package view.component
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import flash.display.*;
    import flash.utils.*;
    import uiresource.tips.*;

    public class Notice extends Sprite
    {
        private var maxCount:int = 5;
        private var msgStack:Vector.<Object>;
        private var curShowCount:int = 0;
        private var labelDic:Dictionary;
        private var delayTimer:int = 0;
        private var delayShowing:Boolean = false;
        private var animateTime:Number = 0.5;
        private var closeTimer:int = 0;

        public function Notice()
        {
            this.msgStack = new Vector.<Object>;
            this.labelDic = new Dictionary();
            return;
        }// end function

        public function add(param1:String, param2:uint) : void
        {
            if (param2 <= 0)
            {
                param2 = 13051156;
            }
            this.msgStack.push({txt:param1, color:param2});
            this.checkShow();
            return;
        }// end function

        public function checkShow() : void
        {
            if (this.delayShowing)
            {
                return;
            }
            if (this.curShowCount >= this.maxCount)
            {
                return;
            }
            if (this.msgStack.length <= 0)
            {
                return;
            }
            this.delayShowing = true;
            this.delayTimer = setTimeout(this.doDelay, this.animateTime * 1000);
            var _loc_2:String = this;
            var _loc_3:* = this.curShowCount + 1;
            _loc_2.curShowCount = _loc_3;
            if (this.closeTimer == 0)
            {
                this.closeTimer = setInterval(this.checkClose, 1000);
            }
            var _loc_1:* = this.msgStack.shift();
            this.doShow(_loc_1);
            return;
        }// end function

        private function checkClose() : void
        {
            var _loc_1:Object = null;
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            for (_loc_1 in this.labelDic)
            {
                
                _loc_2 = this.labelDic[_loc_1];
                _loc_3 = int(_loc_2.closeTime) + 1;
                if (_loc_3 >= 8 - this.maxCount)
                {
                    TweenLite.to(_loc_1, 0.5, {alpha:0, onComplete:this.doKillShow, onCompleteParams:[_loc_1]});
                    continue;
                }
                _loc_2.closeTime = _loc_3;
            }
            return;
        }// end function

        public function doKillShow(param1:NoticeUI) : void
        {
            TweenLite.killTweensOf(param1);
            this.removeChild(param1);
            delete this.labelDic[param1];
            param1 = null;
            var _loc_2:String = this;
            var _loc_3:* = this.curShowCount - 1;
            _loc_2.curShowCount = _loc_3;
            this.checkShow();
            return;
        }// end function

        private function doDelay() : void
        {
            this.delayShowing = false;
            if (this.delayTimer > 0)
            {
                clearTimeout(this.delayTimer);
                this.delayTimer = 0;
            }
            this.checkShow();
            return;
        }// end function

        private function doShow(param1:Object) : void
        {
            var _loc_4:Object = null;
            var _loc_5:TimelineLite = null;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_2:* = new NoticeUI();
            _loc_2.txt_msg.color = param1.color;
            _loc_2.txt_msg.text = param1.txt;
            var _loc_3:* = (-_loc_2.width) / 2;
            _loc_2.x = _loc_3;
            this.addChild(_loc_2);
            for (_loc_4 in this.labelDic)
            {
                
                _loc_6 = this.labelDic[_loc_4];
                _loc_7 = int(_loc_6.index) + 1;
                TweenLite.to(_loc_4, this.animateTime, {y:(-_loc_7) * 28});
                _loc_6.index = _loc_7;
            }
            this.labelDic[_loc_2] = {index:0, closeTime:0};
            _loc_5 = new TimelineLite();
            _loc_5.append(new TweenLite(_loc_2, 0.1, {scaleX:1.5, scaleY:1.5, x:_loc_3 * 1.5, y:-20}));
            _loc_5.append(new TweenLite(_loc_2, 0.1, {scaleX:1, scaleY:1, y:0, x:_loc_3}));
            return;
        }// end function

    }
}
